package com.tk.servlet;

import java.awt.List;
import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tk.entity.Hero;
import com.tk.service.HeroService;
import com.tk.service.impl.HeroServiceImpl;

/**
 * Servlet implementation class findheroServlet
 */
@WebServlet("/findheroServlet")
public class findheroServlet extends HttpServlet {
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException{
			req.setCharacterEncoding("UTF-8");
			resp.setCharacterEncoding("UTF-8");
			
			String tog = req.getParameter("tog");
			int posnum = (int)req.getSession().getAttribute("posnum");
			
			HeroService hSer = new HeroServiceImpl();
			ArrayList<Hero> heroList = hSer.findAll(posnum);
			
			req.setAttribute("heroList", heroList);
			if(tog.equals("kill")){
				req.getRequestDispatcher("/home/kill.jsp").forward(req, resp);
			}
			else if(tog.equals("repos")){
				req.getRequestDispatcher("/home/rePos.jsp").forward(req, resp);
			}
	}
	
}
